package org.yxj.changethemeapp.v

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import org.yxj.changethemeapp.LogUtils

/**
 * @author  on 2024/6/25
 */
class OnTouchViewC : View {

    constructor(context: Context) : this(context, null)
    constructor(context: Context, attributeSet: AttributeSet?) : this(context, attributeSet, 0)
    constructor(context: Context, attributeSet: AttributeSet?, defStyleRes: Int) : super(
        context,
        attributeSet,
        defStyleRes
    )

    var dx = 0f


    /**
     * 执行
     */
    override fun onTouchEvent(event: MotionEvent?): Boolean {
        LogUtils.LOG_V("[OnTouchViewC]->onTouchEvent")
        event?.let {
            when (it.action) {
                MotionEvent.ACTION_DOWN -> {
                    dx = it.x
                }
                MotionEvent.ACTION_UP -> {
                    if (it.x - dx > 150) {
                        parent.requestDisallowInterceptTouchEvent(true)
                        LogUtils.LOG_V("[OnTouchViewC]-> 事件被解开了")
                    }
                }
                MotionEvent.ACTION_UP->{
                    parent.requestDisallowInterceptTouchEvent(false)

                    LogUtils.LOG_V("[OnTouchViewC]-> 事件还给父控件")
                }
            }
        }
        return true
    }
}